/*
 * CheckArgs.cpp
 *
 *  Created on: 17/01/2012
 *      Author: will
 */

#include "../mex_main.h"

void checkArgs_deserializeGraph(int *nrhs, const mxArray **prhs) {
	if (*nrhs != 2)
		mexErrMsgTxt("Number of input arguments not equal to 1 (fileName, )");

	if (!mxIsChar(prhs[1]) || mxGetM(prhs[1]) != 1 || mxIsClass(prhs[1],
			"sparse") || mxIsComplex(prhs[1])) {
		mexErrMsgTxt(
				"Must specify fileName as row vector string");
	}

}

void checkArgs_serializeGraph(int *nrhs, const mxArray **prhs) {
	if (*nrhs != 2)
		mexErrMsgTxt("Number of input arguments not equal to 1 (fileName, )");

	if (!mxIsChar(prhs[1]) || mxGetM(prhs[1]) != 1 || mxIsClass(prhs[1],
			"sparse") || mxIsComplex(prhs[1])) {
		mexErrMsgTxt(
				"Must specify fileName as row vector string");
	}

}


void checkArgs_initialiseGraph(int *nrhs, const mxArray **prhs) {
	if (*nrhs != 5)
		mexErrMsgTxt(
				"Number of input arguments not equal to 4 (numParticles, numNodes, Q, u_mean, )");

	if (mxIsChar(prhs[1]) || mxIsClass(prhs[1], "sparse") || mxIsComplex(
			prhs[1]))
		mexErrMsgTxt("numParticles must be real, full, and nonstring");
	if (mxIsChar(prhs[2]) || mxIsClass(prhs[2], "sparse") || mxIsComplex(
			prhs[2]))
		mexErrMsgTxt("numNodes must be real, full, and nonstring");
	if (mxIsChar(prhs[3]) || mxIsClass(prhs[3], "sparse") || mxIsComplex(
			prhs[3]))
		mexErrMsgTxt("Q must be real, full, and nonstring");
	if (mxIsChar(prhs[4]) || mxIsClass(prhs[4], "sparse") || mxIsComplex(
			prhs[4]))
		mexErrMsgTxt("u_mean must be real, full, and nonstring");

	if (mxGetM(prhs[1]) != 1)
		mexErrMsgTxt("numParticles has an incorrect num of rows (1 x 1)");
	if (mxGetN(prhs[1]) != 1)
		mexErrMsgTxt("numParticles has an incorrect num of cols (1 x 1)");
	if (mxGetM(prhs[2]) != 1)
		mexErrMsgTxt("numNodes has an incorrect num of rows (1 x 1)");
	if (mxGetN(prhs[2]) != 1)
		mexErrMsgTxt("numNodes has an incorrect num of cols (1 x 1)");
	if (mxGetM(prhs[3]) != 3)
		mexErrMsgTxt("Q has an incorrect num of rows (3 x 3)");
	if (mxGetN(prhs[3]) != 3)
		mexErrMsgTxt("Q has an incorrect num of cols (3 x 3)");
	if (mxGetM(prhs[4]) != 3)
		mexErrMsgTxt("u_mean has an incorrect num of rows (3 x 1)");
	if (mxGetN(prhs[4]) != 1)
		mexErrMsgTxt("u_mean has an incorrect num of cols (3 x 1)");

}

void checkArgs_initialiseVision(int *nrhs, const mxArray **prhs) {
	if (*nrhs != 3)
		mexErrMsgTxt("Number of input arguments not equal to 2 (codebookPath, chowLiuPath)");

	if (!mxIsChar(prhs[1]) || mxGetM(prhs[1]) != 1 || mxIsClass(prhs[1],
			"sparse") || mxIsComplex(prhs[1])) {
		mexErrMsgTxt(
				"Must specify codebookPath as row vector string");
	}
	if (!mxIsChar(prhs[2]) || mxGetM(prhs[2]) != 1 || mxIsClass(prhs[2],
			"sparse") || mxIsComplex(prhs[2])) {
		mexErrMsgTxt(
				"Must specify chowLiuPath as row vector string");
	}

}

void checkArgs_initialiseTrajectory(int *nrhs, const mxArray **prhs) {
	if (*nrhs != 3)
		mexErrMsgTxt("Number of input arguments not equal to 2 (frameNum, descriptorPath, )");

	if (mxIsChar(prhs[1]) || mxIsClass(prhs[1], "sparse") || mxIsComplex(
			prhs[1]))
		mexErrMsgTxt("frameNum must be real, full, and nonstring");
	if (!mxIsChar(prhs[2]) || mxGetM(prhs[2]) != 1 || mxIsClass(prhs[2],
			"sparse") || mxIsComplex(prhs[2])) {
		mexErrMsgTxt(
				"Must specify descriptorPath as row vector string");
	}

	if (mxGetM(prhs[1]) != 1)
		mexErrMsgTxt("frameNum has an incorrect num of rows (1 x 1)");
	if (mxGetN(prhs[1]) != 1)
		mexErrMsgTxt("frameNum has an incorrect num of cols (1 x 1)");

}

void checkArgs_initialiseParticles(int *nrhs, const mxArray **prhs) {
	if (*nrhs != 2)
		mexErrMsgTxt("Number of input arguments not equal to 1 (blankFrames, )");

	if (mxIsChar(prhs[1]) || mxIsClass(prhs[1], "sparse") || mxIsComplex(
			prhs[1]))
		mexErrMsgTxt("blankFrames must be real, full, and nonstring");

	if (mxGetM(prhs[1]) != 1)
		mexErrMsgTxt("blankFrames has an incorrect num of rows (1 x 1)");
	if (mxGetN(prhs[1]) != 1)
		mexErrMsgTxt("blankFrames has an incorrect num of cols (1 x 1)");

}

void checkArgs_addNode(int *nrhs, const mxArray **prhs) {
	if (*nrhs != 4)
		mexErrMsgTxt(
				"Number of input arguments not equal to 3 (frameNum, odometry, descriptorPath )");

	if (mxIsChar(prhs[1]) || mxIsClass(prhs[1], "sparse") || mxIsComplex(
			prhs[1]))
		mexErrMsgTxt("frameNum must be real, full, and nonstring");
	if (mxIsChar(prhs[2]) || mxIsClass(prhs[2], "sparse") || mxIsComplex(
			prhs[2]))
		mexErrMsgTxt("odometry must be real, full, and nonstring");
	if (!mxIsChar(prhs[3]) || mxGetM(prhs[3]) != 1 || mxIsClass(prhs[3],
			"sparse") || mxIsComplex(prhs[3])) {
		mexErrMsgTxt(
				"Must specify descriptorPath as row vector string");
	}

	if (mxGetM(prhs[1]) != 1)
		mexErrMsgTxt("frameNum has an incorrect num of rows (1 x 1)");
	if (mxGetN(prhs[1]) != 1)
		mexErrMsgTxt("frameNum has an incorrect num of cols (1 x 1)");
	if (mxGetM(prhs[2]) != 3)
		mexErrMsgTxt("odometry has an incorrect num of rows (3 x 1)");
	if (mxGetN(prhs[2]) != 1)
		mexErrMsgTxt("odometry has an incorrect num of cols (3 x 1)");

}

void checkArgs_updateInformation(int *nrhs, const mxArray **prhs) {
    if (*nrhs != 3)
        mexErrMsgTxt("Number of input arguments not equal to 2 (fabmapPDF, blankFrames, )");

    if (mxIsChar(prhs[1]) || mxIsClass(prhs[1], "sparse") || mxIsComplex(prhs[1]))
        mexErrMsgTxt("fabmapPDF must be real, full, and nonstring");
    if (mxIsChar(prhs[2]) || mxIsClass(prhs[2], "sparse") || mxIsComplex(
    			prhs[2]))
    		mexErrMsgTxt("blankFrames must be real, full, and nonstring");

    const unsigned int numFrames = mxGetM(prhs[1]);

    if (mxGetN(prhs[1]) != numFrames)
        mexErrMsgTxt("fabmapPDF and fabmapPDF have unequal cols (numFrames)");
    if (mxGetM(prhs[2]) != 1)
    	mexErrMsgTxt("blankFrames has an incorrect num of rows (1 x 1)");
	if (mxGetN(prhs[2]) != 1)
		mexErrMsgTxt("blankFrames has an incorrect num of cols (1 x 1)");
}

void checkArgs_pruneNode(int *nrhs, const mxArray **prhs) {
    if (*nrhs != 3)
        mexErrMsgTxt("Number of input arguments not equal to 2 (frameNum, blankFrames, )");

    if (mxIsChar(prhs[1]) || mxIsClass(prhs[1], "sparse") || mxIsComplex(prhs[1]))
        mexErrMsgTxt("frameNum must be real, full, and nonstring");
    if (mxIsChar(prhs[2]) || mxIsClass(prhs[2], "sparse") || mxIsComplex(
				prhs[2]))
			mexErrMsgTxt("blankFrames must be real, full, and nonstring");

    if (mxGetM(prhs[1]) != 1)
        mexErrMsgTxt("frameNum has an incorrect num of rows (1 x 1)");
    if (mxGetN(prhs[1]) != 1)
        mexErrMsgTxt("frameNum has an incorrect num of cols (1 x 1)");
    if (mxGetM(prhs[2]) != 1)
		mexErrMsgTxt("blankFrames has an incorrect num of rows (1 x 1)");
	if (mxGetN(prhs[2]) != 1)
		mexErrMsgTxt("blankFrames has an incorrect num of cols (1 x 1)");


}

void checkArgs_pruneNodeOnline(int *nrhs, const mxArray **prhs) {
	if (*nrhs != 2)
		mexErrMsgTxt("Number of input arguments not equal to 1 (blankFrames, )");

	if (mxIsChar(prhs[1]) || mxIsClass(prhs[1], "sparse") || mxIsComplex(
			prhs[1]))
		mexErrMsgTxt("blankFrames must be real, full, and nonstring");

	if (mxGetM(prhs[1]) != 1)
		mexErrMsgTxt("blankFrames has an incorrect num of rows (1 x 1)");
	if (mxGetN(prhs[1]) != 1)
		mexErrMsgTxt("blankFrames has an incorrect num of cols (1 x 1)");

}

void checkArgs_updateParticlePositions(int *nrhs, const mxArray **prhs) {
	if (*nrhs != 3)
		mexErrMsgTxt("Number of input arguments not equal to 2 (odometry, blankFrames, )");

	if (mxIsChar(prhs[1]) || mxIsClass(prhs[1], "sparse") || mxIsComplex(
			prhs[1]))
		mexErrMsgTxt("odometry must be real, full, and nonstring");
	if (mxIsChar(prhs[2]) || mxIsClass(prhs[2], "sparse") || mxIsComplex(
			prhs[2]))
		mexErrMsgTxt("blankFrames must be real, full, and nonstring");

	if (mxGetM(prhs[1]) != 3)
		mexErrMsgTxt("odometry has an incorrect num of rows (3 x 1)");
	if (mxGetN(prhs[1]) != 1)
		mexErrMsgTxt("odometry has an incorrect num of cols (3 x 1)");
	if (mxGetM(prhs[2]) != 1)
		mexErrMsgTxt("blankFrames has an incorrect num of rows (1 x 1)");
	if (mxGetN(prhs[2]) != 1)
		mexErrMsgTxt("blankFrames has an incorrect num of cols (1 x 1)");

}

void checkArgs_updateParticleWeights(int *nrhs, const mxArray **prhs) {
    if (*nrhs != 3)
        mexErrMsgTxt("Number of input arguments not equal to 2 (fabmapPDF, fabmapAvg, )");

    if (mxIsChar(prhs[1]) || mxIsClass(prhs[1], "sparse") || mxIsComplex(prhs[1]))
        mexErrMsgTxt("fabmapPDF must be real, full, and nonstring");
    if (mxIsChar(prhs[2]) || mxIsClass(prhs[2], "sparse") || mxIsComplex(prhs[2]))
        mexErrMsgTxt("fabmapAvg must be real, full, and nonstring");

    if (mxGetN(prhs[2]) != 1)
        mexErrMsgTxt("fabmapAvg has an incorrect num of cols (numFrames x 1)");

    const unsigned int numFrames = mxGetM(prhs[1]);

    if (mxGetN(prhs[1]) != numFrames)
        mexErrMsgTxt("fabmapPDF and fabmapPDF have unequal cols (numFrames)");
    if (mxGetM(prhs[2]) != numFrames)
        mexErrMsgTxt("fabmapPDF and fabmapAvg have unequal rows (numFrames)");
}

void checkArgs_calculateHypothesis(int *nrhs, const mxArray **prhs) {
	if (*nrhs != 3)
		mexErrMsgTxt(
				"Number of input arguments not equal to 2 (hypothesisDist, blankFrames, )");

	if (mxIsChar(prhs[1]) || mxIsClass(prhs[1], "sparse") || mxIsComplex(
			prhs[1]))
		mexErrMsgTxt("hypothesisDist must be real, full, and nonstring");
	if (mxIsChar(prhs[2]) || mxIsClass(prhs[2], "sparse") || mxIsComplex(
			prhs[2]))
		mexErrMsgTxt("blankFrames must be real, full, and nonstring");

	if (mxGetM(prhs[1]) != 1)
		mexErrMsgTxt("hypothesisDist has an incorrect num of rows (1 x 1)");
	if (mxGetN(prhs[1]) != 1)
		mexErrMsgTxt("hypothesisDist has an incorrect num of cols (1 x 1)");
	if (mxGetM(prhs[2]) != 1)
		mexErrMsgTxt("blankFrames has an incorrect num of rows (1 x 1)");
	if (mxGetN(prhs[2]) != 1)
		mexErrMsgTxt("blankFrames has an incorrect num of cols (1 x 1)");

}

void checkArgs_addLoopClosure(int *nrhs, const mxArray **prhs) {
    if (*nrhs != 2)
        mexErrMsgTxt("Number of input arguments not equal to 1 (particleNo, )");

    if (mxIsChar(prhs[1]) || mxIsClass(prhs[1], "sparse") || mxIsComplex(prhs[1]))
        mexErrMsgTxt("particleNo must be real, full, and nonstring");

    if (mxGetM(prhs[1]) != 1)
        mexErrMsgTxt("particleNo has an incorrect num of rows (1 x 1)");
    if (mxGetN(prhs[1]) != 1)
        mexErrMsgTxt("particleNo has an incorrect num of cols (1 x 1)");


}

void checkArgs_resampleParticles(int *nrhs, const mxArray **prhs) {
	if (*nrhs != 4)
		mexErrMsgTxt(
				"Number of input arguments not equal to 3 (spreadFraction, reverseFraction, blankFrames, )");

	if (mxIsChar(prhs[1]) || mxIsClass(prhs[1], "sparse") || mxIsComplex(
			prhs[1]))
		mexErrMsgTxt("spreadFraction must be real, full, and nonstring");
	if (mxIsChar(prhs[2]) || mxIsClass(prhs[2], "sparse") || mxIsComplex(
			prhs[2]))
		mexErrMsgTxt("reverseFraction must be real, full, and nonstring");
	if (mxIsChar(prhs[3]) || mxIsClass(prhs[3], "sparse") || mxIsComplex(
			prhs[3]))
		mexErrMsgTxt("blankFrames must be real, full, and nonstring");

	if (mxGetM(prhs[1]) != 1)
		mexErrMsgTxt("spreadFraction has an incorrect num of rows (1 x 1)");
	if (mxGetN(prhs[1]) != 1)
		mexErrMsgTxt("spreadFraction has an incorrect num of cols (1 x 1)");
	if (mxGetM(prhs[2]) != 1)
		mexErrMsgTxt("reverseFraction has an incorrect num of rows (1 x 1)");
	if (mxGetN(prhs[2]) != 1)
		mexErrMsgTxt("reverseFraction has an incorrect num of cols (1 x 1)");
	if (mxGetM(prhs[3]) != 1)
		mexErrMsgTxt("blankFrames has an incorrect num of rows (1 x 1)");
	if (mxGetN(prhs[3]) != 1)
		mexErrMsgTxt("blankFrames has an incorrect num of cols (1 x 1)");

}

void checkArgs_buildCodebookFromMap(int *nrhs, const mxArray **prhs) {
	if (*nrhs != 3)
		mexErrMsgTxt("Number of input arguments not equal to 2 (numWords, codebookPath, )");

	if (mxIsChar(prhs[1]) || mxIsClass(prhs[1], "sparse") || mxIsComplex(
			prhs[1]))
		mexErrMsgTxt("numWords must be real, full, and nonstring");
	if (!mxIsChar(prhs[2]) || mxGetM(prhs[2]) != 1 || mxIsClass(prhs[2],
			"sparse") || mxIsComplex(prhs[2])) {
		mexErrMsgTxt(
				"Must specify codebookPath as row vector string");
	}

	if (mxGetM(prhs[1]) != 1)
		mexErrMsgTxt("numWords has an incorrect num of rows (1 x 1)");
	if (mxGetN(prhs[1]) != 1)
		mexErrMsgTxt("numWords has an incorrect num of cols (1 x 1)");

}

void checkArgs_buildChowLiuFromMap(int *nrhs, const mxArray **prhs) {
	if (*nrhs != 3)
		mexErrMsgTxt("Number of input arguments not equal to 2 (infoThreshold, chowLiuPath, )");

	if (mxIsChar(prhs[1]) || mxIsClass(prhs[1], "sparse") || mxIsComplex(
			prhs[1]))
		mexErrMsgTxt("infoThreshold must be real, full, and nonstring");
	if (!mxIsChar(prhs[2]) || mxGetM(prhs[2]) != 1 || mxIsClass(prhs[2],
			"sparse") || mxIsComplex(prhs[2])) {
		mexErrMsgTxt(
				"Must specify chowLiuPath as row vector string");
	}

	if (mxGetM(prhs[1]) != 1)
		mexErrMsgTxt("infoThreshold has an incorrect num of rows (1 x 1)");
	if (mxGetN(prhs[1]) != 1)
		mexErrMsgTxt("infoThreshold has an incorrect num of cols (1 x 1)");

}

void checkArgs_outputLocalGraph(int *nrhs, const mxArray **prhs) {
	if (*nrhs != 3)
		mexErrMsgTxt(
				"Number of input arguments not equal to 2 (particleNo, radius, )");

	if (mxIsChar(prhs[1]) || mxIsClass(prhs[1], "sparse") || mxIsComplex(
			prhs[1]))
		mexErrMsgTxt("particleNo must be real, full, and nonstring");
	if (mxIsChar(prhs[2]) || mxIsClass(prhs[2], "sparse") || mxIsComplex(
			prhs[2]))
		mexErrMsgTxt("radius must be real, full, and nonstring");

	if (mxGetM(prhs[1]) != 1)
		mexErrMsgTxt("particleNo has an incorrect num of rows (1 x 1)");
	if (mxGetN(prhs[1]) != 1)
		mexErrMsgTxt("particleNo has an incorrect num of cols (1 x 1)");
	if (mxGetM(prhs[2]) != 1)
		mexErrMsgTxt("radius has an incorrect num of rows (1 x 1)");
	if (mxGetN(prhs[2]) != 1)
		mexErrMsgTxt("radius has an incorrect num of cols (1 x 1)");
}

void checkArgs_outputLocalUpdate(int *nrhs, const mxArray **prhs) {
    if (*nrhs != 4)
        mexErrMsgTxt("Number of input arguments not equal to 3 (odometry, particleNo, maxFrame, )");

    if (mxIsChar(prhs[1]) || mxIsClass(prhs[1], "sparse") || mxIsComplex(prhs[1]))
        mexErrMsgTxt("odometry must be real, full, and nonstring");
    if (mxIsChar(prhs[2]) || mxIsClass(prhs[2], "sparse") || mxIsComplex(prhs[2]))
        mexErrMsgTxt("particleNo must be real, full, and nonstring");
    if (mxIsChar(prhs[3]) || mxIsClass(prhs[3], "sparse") || mxIsComplex(prhs[3]))
        mexErrMsgTxt("maxFrame must be real, full, and nonstring");

    if (mxGetM(prhs[1]) != 3)
        mexErrMsgTxt("odometry has an incorrect num of rows (3 x 1)");
    if (mxGetN(prhs[1]) != 1)
        mexErrMsgTxt("odometry has an incorrect num of cols (3 x 1)");
    if (mxGetM(prhs[2]) != 1)
        mexErrMsgTxt("particleNo has an incorrect num of rows (1 x 1)");
    if (mxGetN(prhs[2]) != 1)
        mexErrMsgTxt("particleNo has an incorrect num of cols (1 x 1)");
    if (mxGetM(prhs[3]) != 1)
        mexErrMsgTxt("maxFrame has an incorrect num of rows (1 x 1)");
	if (mxGetN(prhs[3]) != 1)
		mexErrMsgTxt("maxFrame has an incorrect num of cols (1 x 1)");


}

void checkArgs_outputLocalHypothesis(int *nrhs, const mxArray **prhs) {
    if (*nrhs != 4)
        mexErrMsgTxt("Number of input arguments not equal to 3 (hypothesisDist, particleNo, maxFrame, )");

    if (mxIsChar(prhs[1]) || mxIsClass(prhs[1], "sparse") || mxIsComplex(prhs[1]))
        mexErrMsgTxt("hypothesisDist must be real, full, and nonstring");
    if (mxIsChar(prhs[2]) || mxIsClass(prhs[2], "sparse") || mxIsComplex(prhs[2]))
        mexErrMsgTxt("particleNo must be real, full, and nonstring");
    if (mxIsChar(prhs[3]) || mxIsClass(prhs[3], "sparse") || mxIsComplex(prhs[3]))
        mexErrMsgTxt("maxFrame must be real, full, and nonstring");

    if (mxGetM(prhs[1]) != 1)
        mexErrMsgTxt("hypothesisDist has an incorrect num of rows (1 x 1)");
    if (mxGetN(prhs[1]) != 1)
        mexErrMsgTxt("hypothesisDist has an incorrect num of cols (1 x 1)");
    if (mxGetM(prhs[2]) != 1)
        mexErrMsgTxt("particleNo has an incorrect num of rows (1 x 1)");
    if (mxGetN(prhs[2]) != 1)
        mexErrMsgTxt("particleNo has an incorrect num of cols (1 x 1)");
    if (mxGetM(prhs[3]) != 1)
        mexErrMsgTxt("maxFrame has an incorrect num of rows (1 x 1)");
    if (mxGetN(prhs[3]) != 1)
        mexErrMsgTxt("maxFrame has an incorrect num of cols (1 x 1)");

}

void checkArgs_outputPlan(int *nrhs, const mxArray **prhs) {
    if (*nrhs != 3)
        mexErrMsgTxt("Number of input arguments not equal to 2 (startFrame, goalFrame, )");

    if (mxIsChar(prhs[1]) || mxIsClass(prhs[1], "sparse") || mxIsComplex(prhs[1]))
        mexErrMsgTxt("startFrame must be real, full, and nonstring");
    if (mxIsChar(prhs[2]) || mxIsClass(prhs[2], "sparse") || mxIsComplex(
				prhs[2]))
			mexErrMsgTxt("goalFrame must be real, full, and nonstring");

    if (mxGetM(prhs[1]) != 1)
        mexErrMsgTxt("startFrame has an incorrect num of rows (1 x 1)");
    if (mxGetN(prhs[1]) != 1)
        mexErrMsgTxt("startFrame has an incorrect num of cols (1 x 1)");
    if (mxGetM(prhs[2]) != 1)
		mexErrMsgTxt("goalFrame has an incorrect num of rows (1 x 1)");
	if (mxGetN(prhs[2]) != 1)
		mexErrMsgTxt("goalFrame has an incorrect num of cols (1 x 1)");


}

void checkArgs_updateInformationOnline(int *nrhs, const mxArray **prhs) {};
void checkArgs_updateParticleWeightsOnline(int *nrhs, const mxArray **prhs) {};
void checkArgs_calculateESS(int *nrhs, const mxArray **prhs) {};
void checkArgs_recomputeWords(int *nrhs, const mxArray **prhs) {};
void checkArgs_recomputeInformation(int *nrhs, const mxArray **prhs) {};

void checkArgs_printNodes(int *nrhs, const mxArray **prhs) {};
void checkArgs_printEdges(int *nrhs, const mxArray **prhs) {};
void checkArgs_printParticles(int *nrhs, const mxArray **prhs) {};
void checkArgs_printLocalGraph(int *nrhs, const mxArray **prhs) {};
void checkArgs_printInformation(int *nrhs, const mxArray **prhs) {};

void checkArgs_outputNodes(int *nrhs, const mxArray **prhs) {};
void checkArgs_outputEdges(int *nrhs, const mxArray **prhs) {};
void checkArgs_outputParticles(int *nrhs, const mxArray **prhs) {};
